package dao

import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import javax.inject.{Inject, Singleton}
import scala.concurrent.ExecutionContext.Implicits.global

/** Created by yz on 2018/7/17
  */
@Singleton
class ProkaryoteDao @Inject() (protected val dbConfigProvider: DatabaseConfigProvider)
    extends HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  type MyRow = ProkaryoteRow
  val table = Prokaryote

  def insertAll(rows: List[MyRow]) = db.run(table ++= rows).map(_ => ())

  def deleteAll = db.run(table.delete).map(_ => ())

  def selectAll = db.run(table.result)

  def selectByBioSample(bioSample: String) = db.run(table.filter(_.bioSample === bioSample).result.head)

  def selectByBioSamples(bioSamples: Seq[String]) = db.run(table.filter(_.bioSample.inSetBind(bioSamples)).result)

}
